<template>
  <div>
    <div style="display: flex;justify-content: center;margin-top: 30px">
      <el-card style="width: 80%;margin: 10px">
        <div style="display: flex;border-bottom: 2px solid #8c8c8c">
          <div style="flex: 1;height: 50px;font-size: 25px">用户  <span
              style="color: #409EFF">{{ userName }}</span>  的积分
          </div>
          <div style="height: 50px;font-size: 25px;flex: 1">
            <el-input style="width: 200px;margin: 0 15px" placeholder="请输入用户账户" v-model="user_name" type="number" min="0" :controls="false"></el-input>
            <el-button type="primary" size="medium" @click="load()" style="height: 40px">查询</el-button>
          </div>
        </div>
        <div style="display: flex;align-items: center;justify-content: center;margin-top: 10px">
          <div style="flex: 1;border-right: 1px solid #8c8c8c">
            <div>当前总积分</div>
            <div style="color: #10A200;font-weight: bold;font-size: 24px">{{ points }}</div>
          </div>
          <div style="flex: 1">
            <div style="margin-top: 20px">
            </div>
          </div>
        </div>
      </el-card>
    </div>
    <div style="display: flex;justify-content: center">
      <el-card style="width: 80%;margin: 10px">
        <div style="height: 50px;font-size: 25px">积分明细</div>
        <div style="margin-bottom: 10px">
        </div>
        <el-table ref="shopsTable" :data="tableData" stripe
                  :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
          <el-table-column prop="time" label="时间" align="center"></el-table-column>
          <el-table-column prop="type" label="类型"></el-table-column>
          <el-table-column prop="amount" label="积分数"></el-table-column>
        </el-table>
        <div style="margin: 10px 0">
          <el-pagination
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="pageSize"
              layout="total,  prev, pager, next"
              :total="total">
          </el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "pointList",
  data() {
    return {
      dialogIntegral: false,
      coupon: [],
      integral: '',
      user: JSON.parse(localStorage.getItem('user') || '{}'),
      tableData: [], //表中数据
      originalData: [],
      select: {
        id: "",
        name: "",
        point: "",
        discount: "",
        status: ""
      },
      rules: {
        id: [
          {required: true, message: '请选择优惠券', trigger: 'change'}
        ],
      },
      points: 0,
      pageNum: 1,
      pageSize: 5,
      total: 0,
      user_name:"",
      ID:"",
      userName:"",
    }
  },
  created() {
    this.load();
  },
  methods: {
    load(pageNum) {  //分页查询
      if (pageNum) this.pageNum = pageNum
      this.$request.post('/user_points_list/', {
        "username": this.user_name,
        "page_size": this.pageSize,
        "page_id": this.pageNum,
      }).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.points_detail
          this.points = res.data.points
          this.total = res.data.item_amount
          console.log("tableData", res)
          this.userName = this.user_name
          this.$message.success("查询成功")
        } else {
            this.$message.warning("找不到该用户")
        }
      })
    },
    handleCurrentChange(pageNum) {
      this.load(pageNum)
    }
    ,
  }
}
</script>
<style scoped>
  /deep/ input::-webkit-outer-spin-button,
  /deep/ input::-webkit-inner-spin-button {
      -webkit-appearance: none;
  }
  /deep/ input[type="number"] {
      -moz-appearance: textfield;
  }
  /deep/ inpit {
      border: none
  }
</style>